import { BASIC_FLAG } from "$utils/enum";
import { backfillFormParams } from "$utils/form"
import { getImg } from "$utils/imgs";
import { setAddTitle } from "$utils/setStatusName";

const { PARTICULAR, ADD } = BASIC_FLAG
export default {
  data() {
    return {
      title: "",
    }
  },
  methods: {
    async init(options) {
      console.log(options, "options");
      const { useFlag } = options

      this.addForm.editable = useFlag !== PARTICULAR

      // 设置标题
      this.title = setAddTitle(useFlag, "发布任务")

      // 不是新增回填
      if (useFlag !== ADD) {
        backfillFormParams("", this.addForm, options)
      }

      this.getOptions()
    },
    setHeadImg(item) {
      const url = getImg(item)
      return url
    },
    // 选择颜色
    selctColor(item, flag) {
      if (flag === "color") {
        this.addForm.form.selctColor = item
      } else {
        this.addForm.form.selectBg = item
      }
    },
    colorStyle(bg) {
      return {
        backgroundColor: bg
      }
    }
  }
}
